<?php
/**
 * sql 标签定义
 */
class TagLibSQL extends TagLib {
	protected $tags = array(
		'sql' => array('attr' => 'sql,data', 'close' => 1)
	);
	
	public function _sql($attr, $content) {
		$tag = $this->parseXmlAttr($attr, 'sql');
		
		$sql = isset($tag['sql']) ? $tag['sql'] : '';
		$data = isset($tag['data']) ? $tag['data'] : 'data';  // 数据存储
		
		$s = '<?php $m=new Model(); ';
		$s .= '$' . $data . '=$m->query("'. $sql .'");';
		$s .= 'if(is_array($'.$data.')){ ?>' . $content;
		$s .= '<?php } ?>';
		
		return $s;
	}
}

